package com.ifonly.render;

import com.ifonly.render.factorys.DefaultErrorRenderFactory;
import com.ifonly.render.factorys.JspMainRenderFactory;
import com.ifonly.render.renders.FtlRender;
import com.ifonly.render.renders.JsonRender;
import com.ifonly.render.renders.JspRender;
import com.ifonly.render.renders.TextRender;

/**
 * @author <a href="mailto:ifonlymaster@163.com">ifonly</a>
 * @version 1.0 2015-12-10 13:57
 * @since JDK 1.6
 */
public class RenderFactory {

    private static ErrorRenderFactory errorRenderFactory = new DefaultErrorRenderFactory();
    private static MainRenderFactory mainRenderFactory = new JspMainRenderFactory();

    public static void setErrorRenderFactory(ErrorRenderFactory errorRenderFactory) {
        RenderFactory.errorRenderFactory = errorRenderFactory;
    }

    public static void setMainRenderFactory(MainRenderFactory mainRenderFactory) {
        RenderFactory.mainRenderFactory = mainRenderFactory;
    }


    public static Render getErrorRender(int errorCode) {
        return errorRenderFactory.getRender(errorCode);
    }

    public static Render getRender(String view) {
        return mainRenderFactory.getRender(view);
    }

    public static Render getJspRender(String view) {
        return new JspRender(view);
    }

    public static Render getFtlRender(String view) {
        return new FtlRender(view);
    }

    public static Render getJsonRender(Object object) {
        return new JsonRender(object);
    }

    public static Render getTextRender(String text) {
        return new TextRender(text);
    }
}
